home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_438 / gadgeted / source / gensrc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  45KB  |  1,293 lines

  1. /*----------------------------------------------------------------------*
  2.    gensrc.c Version 2.0 -  © Copyright 1990 Jaba Development
  3.  
  4.    Author : Jan van den Baard
  5.    Purpose: What it's all about, the writing of C or Assembler source
  6.  *----------------------------------------------------------------------*/
  7.  
  8. extern struct GadgetList     Gadgets;
  9. extern struct Window        *MainWindow;
  10. extern struct Screen        *MainScreen;
  11. extern struct ge_prefs       prefs;
  12. extern struct Gadget         TextGadget;
  13. extern struct FileRequester *IODir;
  14. extern BOOL                  REQUESTER, WBSCREEN;
  15. extern UBYTE                 name[256], wdt[80], wlb[MAXLABEL];
  16. extern ULONG                 WindowFlags, IDCMPFlags;
  17. extern USHORT                BackFill, GadgetCount;
  18.  
  19. struct GadgetList Borders;
  20.  
  21. /*
  22.  * split up the normal and 'BORDERONLY' gadgets in seperate lists
  23.  */
  24. static VOID split()
  25. {
  26.     register struct MyGadget *tmp;
  27.  
  28.     NewList((void *)&Borders);
  29.  
  30.     if(!Gadgets.Head->Succ) return;
  31.  
  32.     while(1)
  33.     {   tmp = Gadgets.Head;
  34.         while(1)
  35.         {   if(TestBits((ULONG)tmp->SpecialFlags,BORDERONLY)) break;
  36.             if((tmp = tmp->Succ) == (struct MyGadget *)&Gadgets.Tail) return;
  37.         }
  38.         Remove((void *)tmp);
  39.         AddHead((void *)&Borders,(void *)tmp);
  40.     }
  41. }
  42.  
  43. /*
  44.  * join the normal and 'BORDERONLY' gadgets again
  45.  */
  46. static VOID join()
  47. {
  48.     register struct MyGadget *tmp;
  49.  
  50.     if(!Gadgets.Head->Succ) return;
  51.  
  52.     while((tmp = (struct MyGadget *)RemHead((void *)&Borders)))
  53.          AddTail((void *)&Gadgets,(void *)tmp);
  54. }
  55.  
  56. /*
  57.  * write the IDCMPFlags
  58.  */
  59. static VOID WriteIFlags(file)
  60.     BPTR file;
  61. {
  62.     if(NOT IDCMPFlags) { WriteFormat(file,"NULL"); return; }
  63.     if(TestBits(IDCMPFlags,SIZEVERIFY))
  64.        WriteFormat(file,"SIZEVERIFY+");
  65.     if(TestBits(IDCMPFlags,NEWSIZE))
  66.        WriteFormat(file,"NEWSIZE+");
  67.     if(TestBits(IDCMPFlags,REFRESHWINDOW))
  68.        WriteFormat(file,"REFRESHWINDOW+");
  69.     if(TestBits(IDCMPFlags,ACTIVEWINDOW))
  70.        WriteFormat(file,"ACTIVEWINDOW+");
  71.     if(TestBits(IDCMPFlags,INACTIVEWINDOW))
  72.        WriteFormat(file,"INACTIVEWINDOW+");
  73.     if(TestBits(IDCMPFlags,GADGETDOWN))
  74.        WriteFormat(file,"GADGETDOWN+");
  75.     if(TestBits(IDCMPFlags,GADGETUP))
  76.        WriteFormat(file,"GADGETUP+");
  77.     if(TestBits(IDCMPFlags,CLOSEWINDOW))
  78.        WriteFormat(file,"CLOSEWINDOW+");
  79.     if(TestBits(IDCMPFlags,REQSET))
  80.        WriteFormat(file,"REQSET+");
  81.     if(TestBits(IDCMPFlags,REQCLEAR))
  82.        WriteFormat(file,"REQCLEAR+");
  83.     if(TestBits(IDCMPFlags,REQVERIFY))
  84.        WriteFormat(file,"REQVERIFY+");
  85.     if(TestBits(IDCMPFlags,MENUPICK))
  86.        WriteFormat(file,"MENUPICK+");
  87.     if(TestBits(IDCMPFlags,MENUVERIFY))
  88.        WriteFormat(file,"MENUVERIFY+");
  89.     if(TestBits(IDCMPFlags,MOUSEBUTTONS))
  90.        WriteFormat(file,"MOUSEBUTTONS+");
  91.     if(TestBits(IDCMPFlags,MOUSEMOVE))
  92.        WriteFormat(file,"MOUSEMOVE+");
  93.     if(TestBits(IDCMPFlags,DELTAMOVE))
  94.        WriteFormat(file,"DELTAMOVE+");
  95.     if(TestBits(IDCMPFlags,INTUITICKS))
  96.        WriteFormat(file,"INTUITICKS+");
  97.     if(TestBits(IDCMPFlags,NEWPREFS))
  98.        WriteFormat(file,"NEWPREFS+");
  99.     if(TestBits(IDCMPFlags,DISKINSERTED))
  100.        WriteFormat(file,"DISKINSERTED+");
  101.     if(TestBits(IDCMPFlags,DISKREMOVED))
  102.        WriteFormat(file,"DISKREMOVED+");
  103.     if(TestBits(IDCMPFlags,RAWKEY))
  104.        WriteFormat(file,"RAWKEY+");
  105.     if(TestBits(IDCMPFlags,VANILLAKEY))
  106.        WriteFormat(file,"VANILLAKEY+");
  107.     if(TestBits(IDCMPFlags,WBENCHMESSAGE))
  108.        WriteFormat(file,"WBENCHMESSAGE+");
  109.     if(TestBits(IDCMPFlags,LONELYMESSAGE))
  110.        WriteFormat(file,"LONELYMESSAGE+");
  111.     Seek(file,-1,OFFSET_CURRENT);
  112. }
  113.  
  114. /*
  115.  * write the window flags
  116.  */
  117. static VOID WriteWFlags(file)
  118.     BPTR file;
  119. {
  120.     if(NOT WindowFlags)
  121.     {   WriteFormat(file,"NULL");
  122.         return;
  123.     }
  124.     if(TestBits(WindowFlags,WINDOWSIZING))
  125.       WriteFormat(file,"WINDOWSIZING+");
  126.     if(TestBits(WindowFlags,WINDOWDRAG))
  127.       WriteFormat(file,"WINDOWDRAG+");
  128.     if(TestBits(WindowFlags,WINDOWDEPTH))
  129.       WriteFormat(file,"WINDOWDEPTH+");
  130.     if(TestBits(WindowFlags,WINDOWCLOSE))
  131.       WriteFormat(file,"WINDOWCLOSE+");
  132.     if(TestBits(WindowFlags,SIZEBRIGHT))
  133.       WriteFormat(file,"SIZEBRIGHT+");
  134.     if(TestBits(WindowFlags,SIZEBBOTTOM))
  135.       WriteFormat(file,"SIZEBBOTTOM+");
  136.     if(TestBits(WindowFlags,NOCAREREFRESH))
  137.       WriteFormat(file,"NOCAREREFRESH+");
  138.     if(TestBits(WindowFlags,SIMPLE_REFRESH))
  139.       WriteFormat(file,"SIMPLE_REFRESH+");
  140.     if(TestBits(WindowFlags,SMART_REFRESH))
  141.       WriteFormat(file,"SMART_REFRESH+");
  142.     if(TestBits(WindowFlags,SUPER_BITMAP))
  143.       WriteFormat(file,"SUPER_BITMAP+");
  144.     if(TestBits(WindowFlags,BACKDROP))
  145.       WriteFormat(file,"BACKDROP+");
  146.     if(TestBits(WindowFlags,GIMMEZEROZERO))
  147.       WriteFormat(file,"GIMMEZEROZERO+");
  148.     if(TestBits(WindowFlags,BORDERLESS))
  149.       WriteFormat(file,"BORDERLESS+");
  150.     if(TestBits(WindowFlags,ACTIVATE))
  151.       WriteFormat(file,"ACTIVATE+");
  152.     if(TestBits(WindowFlags,REPORTMOUSE))
  153.       WriteFormat(file,"REPORTMOUSE+");
  154.     if(TestBits(WindowFlags,RMBTRAP))
  155.       WriteFormat(file,"RMBTRAP+");
  156.     Seek(file,-1,OFFSET_CURRENT);
  157. }
  158.  
  159. /*
  160.  * write the gadget flags
  161.  */
  162. static VOID WriteFlags(file,gad)
  163.     BPTR            file;
  164.     struct MyGadget *gad;
  165. {
  166.     struct Gadget *gadget;
  167.     ULONG   flags;
  168.  
  169.     gadget = &gad->Gadget;
  170.     flags   = (ULONG)gadget->Flags;
  171.  
  172.     if(NOT flags)
  173.     {   WriteFormat(file,"GADGHCOMP");
  174.         return;
  175.     }
  176.     if((TestBits(flags,GADGHIMAGE)) AND (TestBits(flags,GADGHBOX)))
  177.       WriteFormat(file,"GADGHNONE+");
  178.     else if(TestBits(flags,GADGHIMAGE))
  179.       WriteFormat(file,"GADGHIMAGE+");
  180.     else if(TestBits(flags,GADGHBOX))
  181.       WriteFormat(file,"GADGHBOX+");
  182.     else WriteFormat(file,"GADGHCOMP+");
  183.     if(TestBits(flags,GRELBOTTOM))
  184.       WriteFormat(file,"GRELBOTTOM+");
  185.     if(TestBits(flags,GRELRIGHT))
  186.       WriteFormat(file,"GRELRIGHT+");
  187.     if(TestBits(flags,GRELWIDTH))
  188.       WriteFormat(file,"GRELWIDTH+");
  189.     if(TestBits(flags,GRELHEIGHT))
  190.       WriteFormat(file,"GRELHEIGHT+");
  191.     if(TestBits(flags,GADGIMAGE))
  192.       WriteFormat(file,"GADGIMAGE+");
  193.     if(TestBits(flags,SELECTED))
  194.       WriteFormat(file,"SELECTED+");
  195.     if(TestBits((ULONG)gad->SpecialFlags,GADGETOFF))
  196.       WriteFormat(file,"GADGDISABLED+");
  197.     Seek(file,-1,OFFSET_CURRENT);
  198. }
  199.  
  200. /*
  201.  * write the activation gadget flags
  202.  */
  203. static VOID WriteActivation(file,gad)
  204.     BPTR            file;
  205.     struct MyGadget *gad;
  206. {
  207.     struct Gadget   *gadget;
  208.     ULONG  act;
  209.  
  210.     gadget = &gad->Gadget;
  211.     act    = (ULONG)gadget->Activation;
  212.  
  213.     if(TestBits(act,TOGGLESELECT))
  214.       WriteFormat(file,"TOGGLESELECT+");
  215.     if(NOT TestBits(gad->SpecialFlags,NOSIGNAL))
  216.     {   if(TestBits(act,RELVERIFY))
  217.           WriteFormat(file,"RELVERIFY+");
  218.         if(TestBits(act,GADGIMMEDIATE))
  219.           WriteFormat(file,"GADGIMMEDIATE+");
  220.     }
  221.     if(TestBits(act,RIGHTBORDER))
  222.       WriteFormat(file,"RIGHTBORDER+");
  223.     if(TestBits(act,LEFTBORDER))
  224.       WriteFormat(file,"LEFTBORDER+");
  225.     if(TestBits(act,TOPBORDER))
  226.       WriteFormat(file,"TOPBORDER+");
  227.     if(TestBits(act,BOTTOMBORDER))
  228.       WriteFormat(file,"BOTTOMBORDER+");
  229.     if(TestBits(act,STRINGCENTER))
  230.       WriteFormat(file,"STRINGCENTER+");
  231.     if(TestBits(act,STRINGRIGHT))
  232.       WriteFormat(file,"STRINGRIGHT+");
  233.     if(TestBits(act,LONGINT))
  234.       WriteFormat(file,"LONGINT+");
  235.     if(TestBits(act,ALTKEYMAP))
  236.       WriteFormat(file,"ALTKEYMAP+");
  237.     if(TestBits(act,BOOLEXTEND))
  238.       WriteFormat(file,"BOOLEXTEND+");
  239.     if(TestBits(act,ENDGADGET))
  240.       WriteFormat(file,"ENDGADGET+");
  241.     if(TestBits(act,FOLLOWMOUSE))
  242.       WriteFormat(file,"FOLLOWMOUSE+");
  243.     Seek(file,-1,OFFSET_CURRENT);
  244. }
  245.  
  246. /*
  247.  * write the gadget type
  248.  */
  249. static VOID WriteType(file,gad)
  250.     BPTR            file;
  251.     struct MyGadget *gad;
  252. {
  253.     struct Gadget   *gadget;
  254.     ULONG   type;
  255.  
  256.     gadget = &gad->Gadget;
  257.     type   = (ULONG)gadget->GadgetType;
  258.  
  259.     if(TestBits(type,PROPGADGET))
  260.       WriteFormat(file,"PROPGADGET+");
  261.     else if(TestBits(type,STRGADGET))
  262.       WriteFormat(file,"STRGADGET+");
  263.     else if(TestBits(type,BOOLGADGET))
  264.       WriteFormat(file,"BOOLGADGET+");
  265.     if(TestBits((ULONG)gad->SpecialFlags,GZZGADGET))
  266.       WriteFormat(file,"GZZGADGET+");
  267.     if(REQUESTER)
  268.       WriteFormat(file,"REQGADGET+");
  269.     Seek(file,-1,OFFSET_CURRENT);
  270. }
  271.  
  272. /*
  273.  * write the draw modes
  274.  */
  275. static VOID WriteDrMd(file,drmd,mode)
  276.     BPTR file;
  277.     ULONG drmd;
  278.     BOOL  mode; /* TRUE = Asm, FALSE = C */
  279. {
  280.     if(TestBits(drmd,JAM2))
  281.     {   if(mode) WriteFormat(file,"RP_JAM2+");
  282.         else     WriteFormat(file,"JAM2+");
  283.     }
  284.     else if(TestBits(drmd,JAM1))
  285.     {   if(mode) WriteFormat(file,"RP_JAM1+");
  286.         else     WriteFormat(file,"JAM1+");
  287.     }
  288.     if(TestBits(drmd,COMPLEMENT))
  289.     if(mode) WriteFormat(file,"RP_COMPLEMENT+");
  290.     else     WriteFormat(file,"COMPLEMENT+");
  291.     if(TestBits(drmd,INVERSVID))
  292.     if(mode) WriteFormat(file,"RP_INVERSVID+");
  293.     else     WriteFormat(file,"INVERSVID+");
  294.     Seek(file,-1,OFFSET_CURRENT);
  295. }
  296.  
  297. /*
  298.  * write the propinfo flags
  299.  */
  300. static VOID WritePFlags(file,info)
  301.     BPTR            file;
  302.     struct PropInfo *info;
  303. {
  304.     ULONG flags;
  305.  
  306.     flags = (ULONG)info->Flags;
  307.  
  308.     if(TestBits(flags,AUTOKNOB))
  309.      WriteFormat(file,"AUTOKNOB+");
  310.     if(TestBits(flags,FREEHORIZ))
  311.      WriteFormat(file,"FREEHORIZ+");
  312.     if(TestBits(flags,FREEVERT))
  313.      WriteFormat(file,"FREEVERT+");
  314.     if(TestBits(flags,PROPBORDERLESS))
  315.      WriteFormat(file,"PROPBORDERLESS+");
  316.     Seek(file,-1,OFFSET_CURRENT);
  317. }
  318.  
  319. /*
  320.  * write the assembler border structure
  321.  */
  322. static VOID WriteAsmBorder(file,gadget)
  323.     BPTR            file;
  324.     struct MyGadget *gadget;
  325. {
  326.     struct Border *border;
  327.     SHORT         *XY;
  328.     COUNT    i;
  329.  
  330.     border = (struct Border *)gadget->Gadget.GadgetRender;
  331.     XY     = border->XY;
  332.  
  333.     WriteFormat(file,"%s_pairs:\n    DC.W ",&gadget->GadgetLabel);
  334.     for(i=0;i<10;i++) WriteFormat(file,"%ld,",XY[i]);
  335.     Seek(file,-1,OFFSET_CURRENT);
  336.     WriteFormat(file,"\n\n");
  337.     WriteFormat(file,"%s_bord:\n",&gadget->GadgetLabel);
  338.     WriteFormat(file,"    DC.W    %ld,%ld\n",border->LeftEdge,border->TopEdge);
  339.     WriteFormat(file,"    DC.B    %ld,%ld\n",border->FrontPen,border->BackPen);
  340.     WriteFormat(file,"    DC.B    ");
  341.     WriteDrMd(file,(ULONG)border->DrawMode,TRUE);
  342.     WriteFormat(file,"\n    DC.B    %ld\n",border->Count);
  343.     WriteFormat(file,"    DC.L    %s_pairs,0\n\n",&gadget->GadgetLabel);
  344. }
  345.  
  346. /*
  347.  * write the assembler image
  348.  */
  349. static VOID WriteAsmImage(file,gadget,which)
  350.     BPTR            file;
  351.     struct MyGadget *gadget;
  352.     UBYTE           which;
  353. {
  354.     struct Image    *image;
  355.     register USHORT *data;
  356.     register COUNT  i,ii;
  357.     ULONG           data_size;
  358.  
  359.     if(which == RENDER) image = (struct Image *)gadget->Gadget.GadgetRender;
  360.     else                image = (struct Image *)gadget->Gadget.SelectRender;
  361.     data  = image->ImageData;
  362.  
  363.     if(which != STDPRP)
  364.     {   if(which == SELECT)
  365.           WriteFormat(file,"%s_hdata:\n",gadget->GadgetLabel);
  366.         else
  367.           WriteFormat(file,"%s_data:\n",gadget->GadgetLabel);
  368.         data_size = (RASSIZE(image->Width,image->Height) * image->Depth);
  369.         for(i=0;i<(data_size >> 1);i+=8)
  370.         {   WriteFormat(file,"    DC.W    ");
  371.             for(ii=0;ii<8;ii++)
  372.             {   if(i+ii < (data_size >> 1)) WriteFormat(file,"$%04lx,",data[i+ii]);
  373.             }
  374.             Seek(file,-1,OFFSET_CURRENT);
  375.             WriteFormat(file,"\n");
  376.         }
  377.         WriteFormat(file,"\n");
  378.     }
  379.     if(which == SELECT)
  380.       WriteFormat(file,"%s_himage:\n",&gadget->GadgetLabel);
  381.     else
  382.       WriteFormat(file,"%s_image:\n",&gadget->GadgetLabel);
  383.     WriteFormat(file,"    DC.W    %ld,%ld\n",image->LeftEdge,image->TopEdge);
  384.     WriteFormat(file,"    DC.W    %ld,%ld\n",image->Width,image->Height);
  385.     WriteFormat(file,"    DC.W    %ld\n",image->Depth);
  386.     if(which != STDPRP)
  387.     {   if(which == SELECT)
  388.           WriteFormat(file,"    DC.L    %s_hdata\n",&gadget->GadgetLabel);
  389.         else
  390.           WriteFormat(file,"    DC.L    %s_data\n",&gadget->GadgetLabel);
  391.     }
  392.     else WriteFormat(file,"    DC.L    0\n");
  393.     WriteFormat(file,"    DC.B    $%02lx\n",image->PlanePick);
  394.     WriteFormat(file,"    DC.B    $%02lx\n",image->PlaneOnOff);
  395.     WriteFormat(file,"    DC.L    0\n\n");
  396. }
  397.  
  398. /*
  399.  * write the assembler prop info structure
  400.  */
  401. static VOID WriteAsmPinfo(file,gadget)
  402.     BPTR            file;
  403.     struct MyGadget *gadget;
  404. {
  405.     struct PropInfo *info;
  406.  
  407.     info = (struct PropInfo *)gadget->Gadget.SpecialInfo;
  408.     WriteFormat(file,"%s_info:\n",&gadget->GadgetLabel);
  409.     WriteFormat(file,"    DC.W    ");
  410.     WritePFlags(file,info);
  411.     WriteFormat(file,"\n    DC.W    $%04lx\n",info->HorizPot);
  412.     WriteFormat(file,"    DC.W    $%04lx\n",info->VertPot);
  413.     WriteFormat(file,"    DC.W    $%04lx\n",info->HorizBody);
  414.     WriteFormat(file,"    DC.W    $%04lx\n",info->VertBody);
  415.     WriteFormat(file,"    DC.W    0,0,0,0,0,0\n\n");
  416. }
  417.  
  418. /*
  419.  * write the assembler string info structure
  420.  */
  421. static VOID WriteAsmSinfo(file,gadget)
  422.     BPTR            file;
  423.     struct MyGadget *gadget;
  424. {
  425.     struct StringInfo *info;
  426.  
  427.     info = (struct StringInfo *)gadget->Gadget.SpecialInfo;
  428.     WriteFormat(file,"%s_info:\n",&gadget->GadgetLabel);
  429.     WriteFormat(file,"    DC.L    %s_buf\n",&gadget->GadgetLabel);
  430.     if(info->UndoBuffer)
  431.        WriteFormat(file,"    DC.L    %s_ubuf\n",&gadget->GadgetLabel);
  432.     else
  433.        WriteFormat(file,"    DC.L    0\n");
  434.     WriteFormat(file,"    DC.W    0,%ld\n",info->MaxChars);
  435.     WriteFormat(file,"    DC.W    0,0,0,0,0,0\n");
  436.     WriteFormat(file,"    DC.L    0,0,0\n\n");
  437.     WriteFormat(file,"%s_buf:\n",&gadget->GadgetLabel);
  438.     WriteFormat(file,"    DC.B    '%s',0\n",info->Buffer);
  439.     WriteFormat(file,"    DCB.B   %ld,0\n",info->MaxChars - strlen((char *)info->Buffer) -1);
  440.     WriteFormat(file,"    CNOP    0,2\n\n");
  441.     if(info->UndoBuffer)
  442.     {   WriteFormat(file,"%s_ubuf:\n    DCB.B    %ld,0\n",&gadget->GadgetLabel,info->MaxChars);
  443.         WriteFormat(file,"    CNOP    0,2\n\n");
  444.     }
  445. }
  446.  
  447. /*
  448.  * write the assembler gadget structure
  449.  */
  450. static VOID WriteAsmGadget(file,gadget)
  451.     BPTR            file;
  452.     struct MyGadget *gadget;
  453. {
  454.     struct Gadget   *gad;
  455.     struct MyGadget *next;
  456.  
  457.     gad = &gadget->Gadget;
  458.  
  459.     WriteFormat(file,"%s_ID   EQU     %ld\n\n",&gadget->GadgetLabel,gad->GadgetID);
  460.  
  461.     WriteFormat(file,"%s:\n",&gadget->GadgetLabel);
  462.     if(gadget == Gadgets.Head)
  463.     {   if((TextGadget.GadgetText) OR
  464.            (Borders.TailPred != (struct MyGadget *)&Borders))
  465.         {   if(NOT REQUESTER) WriteFormat(file,"    DC.L    rnd\n");
  466.             else WriteFormat(file,"    DC.L    0\n");
  467.         }
  468.         else WriteFormat(file,"    DC.L    0\n");
  469.     }
  470.     else
  471.        WriteFormat(file,"    DC.L    %s\n",&(gadget->Pred->GadgetLabel));
  472.     WriteFormat(file,"    DC.W    %ld,%ld\n",gad->LeftEdge,gad->TopEdge);
  473.     WriteFormat(file,"    DC.W    %ld,%ld\n",gad->Width,gad->Height);
  474.     WriteFormat(file,"    DC.W    ");
  475.     WriteFlags(file,gadget);
  476.     WriteFormat(file,"\n    DC.W    ");
  477.     WriteActivation(file,gadget);
  478.     WriteFormat(file,"\n    DC.W    ");
  479.     WriteType(file,gadget);
  480.  
  481.     if((TestBits((ULONG)gad->Flags,GADGIMAGE)) ||
  482.        (TestBits((ULONG)gad->GadgetType,PROPGADGET)))
  483.       WriteFormat(file,"\n    DC.L    %s_image\n",&gadget->GadgetLabel);
  484.     else
  485.       WriteFormat(file,"\n    DC.L    %s_bord\n",&gadget->GadgetLabel);
  486.     if((TestBits((ULONG)gad->Flags,GADGHIMAGE)) AND
  487.        (NOT TestBits((ULONG)gad->Flags,GADGHBOX)))
  488.       WriteFormat(file,"    DC.L    %s_himage\n",&gadget->GadgetLabel);
  489.     else
  490.       WriteFormat(file,"    DC.L    0\n");
  491.     if(gad->GadgetText)
  492.       WriteFormat(file,"    DC.L    %s_text0,0\n",&gadget->GadgetLabel);
  493.     else
  494.       WriteFormat(file,"    DC.L    0,0\n");
  495.     if(gad->SpecialInfo)
  496.       WriteFormat(file,"    DC.L    %s_info\n",&gadget->GadgetLabel);
  497.     else
  498.       WriteFormat(file,"    DC.L    0\n");
  499.     WriteFormat(file,"    DC.W    %s_ID\n    DC.L    0\n\n",&gadget->GadgetLabel);
  500. }
  501.  
  502. /*
  503.  * write the assembler IntuitText structures
  504.  */
  505. static VOID WriteAsmTexts(file,gadget)
  506.     BPTR            file;
  507.     struct MyGadget *gadget;
  508. {
  509.     register struct IntuiText *itext;
  510.     COUNT    i=0;
  511.  
  512.     if((itext = gadget->Gadget.GadgetText))
  513.     {   WriteFormat(file,"%s_text%ld:\n",&gadget->GadgetLabel,i);
  514.         while(1)
  515.         {   WriteFormat(file,"    DC.B    %ld,%ld\n",itext->FrontPen,itext->BackPen);
  516.             WriteFormat(file,"    DC.B    ");
  517.             WriteDrMd(file,itext->DrawMode);
  518.             WriteFormat(file,"\n    DC.W    %ld,%ld\n",itext->LeftEdge,itext->TopEdge);
  519.             WriteFormat(file,"    DC.L    0\n");
  520.             WriteFormat(file,"    DC.L    %s_itext%ld\n",&gadget->GadgetLabel,i);
  521.             if(itext->NextText)
  522.               WriteFormat(file,"    DC.L    %s_text%ld\n\n",&gadget->GadgetLabel,i+1);
  523.             else
  524.               WriteFormat(file,"    DC.L    0\n\n");
  525.             WriteFormat(file,"%s_itext%ld:\n",&gadget->GadgetLabel,i++);
  526.             WriteFormat(file,"    DC.B    '%s',0\n",itext->IText);
  527.             WriteFormat(file,"    CNOP    0,2\n\n");
  528.             if(!(itext = itext->NextText)) break;
  529.             WriteFormat(file,"%s_text%ld\n",&gadget->GadgetLabel,i);
  530.         }
  531.     }
  532. }
  533.  
  534. /*
  535.  * write the assembler new screen structure
  536.  */
  537. static VOID WriteAsmScreen(file)
  538.     BPTR file;
  539. {
  540.     WriteFormat(file,"ns:\n");
  541.     WriteFormat(file,"    DC.W    0,0,%ld,%ld\n",MainScreen->Width,MainScreen->Height);
  542.     WriteFormat(file,"    DC.W    %ld\n",MainScreen->BitMap.Depth);
  543.     WriteFormat(file,"    DC.B    -1,-1\n");
  544.     if(MainScreen->BitMap.Depth == 5) WriteFormat(file,"    DC.W    0\n");
  545.     else WriteFormat(file,"    DC.W    HIRES\n");
  546.     WriteFormat(file,"    DC.W    CUSTOMSCREEN\n");
  547.     WriteFormat(file,"    DC.L    0,0,0,0\n\n");
  548. }
  549.  
  550. /*
  551.  * write the assembler window/requester structure
  552.  */
  553. static VOID WriteAsmRW(file)
  554.     BPTR file;
  555. {
  556.     if(REQUESTER)
  557.     {   WriteFormat(file,"requester:\n    DC.L    0\n");
  558.         WriteFormat(file,"    DC.W    %ld,%ld,",(MainWindow->LeftEdge + MainWindow->BorderLeft),
  559.                                                 (MainWindow->TopEdge + MainWindow->BorderTop));
  560.         WriteFormat(file,"%ld,%ld\n",MainWindow->GZZWidth,MainWindow->GZZHeight);
  561.         if(GadgetCount)
  562.             WriteFormat(file,"    DC.W    0,0\n    DC.L    %s,",&Gadgets.TailPred->GadgetLabel);
  563.         else
  564.             WriteFormat(file,"    DC.W    0,0\n    DC.L    0");
  565.         if(Borders.TailPred != (struct MyGadget *)&Borders)
  566.           WriteFormat(file,"rnd_border0\n");
  567.         else
  568.           WriteFormat(file,"0\n");
  569.         if(TextGadget.GadgetText) WriteFormat(file,"    DC.L    rnd_text0\n");
  570.         else WriteFormat(file,"    DC.L    0\n");
  571.         WriteFormat(file,"    DC.W    0\n    DC.B    %ld\n",BackFill);
  572.         WriteFormat(file,"    DC.L    0\n    DCB.B   32,0\n    DC.L    0,0\n    DCB.B    36,0\n\n");
  573.     }
  574.     else
  575.     {   WriteFormat(file,"%s:\n",&wlb);
  576.         WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld\n",MainWindow->LeftEdge,MainWindow->TopEdge,
  577.                                                          MainWindow->Width,MainWindow->Height);
  578.         WriteFormat(file,"    DC.B    %ld,%ld\n",MainWindow->DetailPen,MainWindow->BlockPen);
  579.         WriteFormat(file,"    DC.L    ");
  580.         WriteIFlags(file);
  581.         WriteFormat(file,"\n    DC.L    ");
  582.         WriteWFlags(file);
  583.         WriteFormat(file,"\n");
  584.         if(GadgetCount)
  585.             WriteFormat(file,"    DC.L    %s,0\n",Gadgets.TailPred->GadgetLabel);
  586.         else
  587.             WriteFormat(file,"    DC.L    0,0\n");
  588.         WriteFormat(file,"    DC.L    %s_title\n",&wlb);
  589.         WriteFormat(file,"    DC.L    0,0\n");
  590.         WriteFormat(file,"    DC.W    %ld,%ld,%ld,%ld,",MainWindow->MinWidth,
  591.                                                         MainWindow->MinHeight,
  592.                                                         MainWindow->MaxWidth,
  593.                                                         MainWindow->MaxHeight);
  594.         if(WBSCREEN) WriteFormat(file,"WBENCHSCREEN\n\n");
  595.         else         WriteFormat(file,"CUSTOMSCREEN\n\n");
  596.         WriteFormat(file,"%s_title:\n    DC.B    '%s',0\n    CNOP    0,2\n\n",&wlb,&wdt);
  597.     }
  598. }
  599.  
  600. /*
  601.  * write the assembler window/requester texts
  602.  */
  603. static VOID WriteAsmWDT(file)
  604.     BPTR file;
  605. {
  606.     register struct IntuiText *t, *t1;
  607.     register UCOUNT i = 0;
  608.  
  609.     if(NOT TextGadget.GadgetText) return;
  610.  
  611.     t = t1 = TextGadget.GadgetText;
  612.     WriteFormat(file,"rnd_text%ld:\n",i);
  613.     while(1)
  614.     {   WriteFormat(file,"    DC.B    %ld,%ld\n",t->FrontPen,t->BackPen);
  615.         WriteFormat(file,"    DC.B    ");
  616.         WriteDrMd(file,t->DrawMode);
  617.         WriteFormat(file,"\n    DC.W    %ld,%ld\n",t->LeftEdge,t->TopEdge);
  618.         WriteFormat(file,"    DC.L    0\n");
  619.         WriteFormat(file,"    DC.L    rnd_itext%ld\n",i);
  620.         if(t->NextText)
  621.           WriteFormat(file,"    DC.L    rnd_text%ld\n\n",i+1);
  622.         else
  623.           WriteFormat(file,"    DC.L    0\n\n");
  624.         WriteFormat(file,"rnd_itext%ld:\n",i++);
  625.         WriteFormat(file,"    DC.B    '%s',0\n",t->IText);
  626.         WriteFormat(file,"    CNOP    0,2\n\n");
  627.         if(!(t = t->NextText)) break;
  628.         WriteFormat(file,"rnd_text%ld\n",i);
  629.     }
  630. }
  631.  
  632. /*
  633.  * write assembler special render gadget
  634.  */
  635. static VOID WriteAsmCRG(file)
  636.     BPTR file;
  637. {
  638.     if((TextGadget.GadgetText) OR
  639.        (Borders.TailPred != (struct MyGadget *)&Borders))
  640.     {   if(NOT REQUESTER)
  641.         {   WriteFormat(file,"rnd:\n");
  642.             WriteFormat(file,"    DC.L    0\n    DC.W    0,0,1,1,GADGHNONE,0,BOOLGADGET\n");
  643.            if(Borders.TailPred != (struct MyGadget *)&Borders)
  644.              WriteFormat(file,"    DC.L    rnd_border0,");
  645.            else
  646.              WriteFormat(file,"    DC.L    0,");
  647.            if(TextGadget.GadgetText)
  648.              WriteFormat(file,"0,rnd_text0,");
  649.            else
  650.              WriteFormat(file,"0,0,");
  651.              WriteFormat(file,"0,0\n    DC.W    0\n    DC.L    0\n\n");
  652.        }
  653.     }
  654. }
  655.  
  656. /*
  657.  * write the assembler border structures
  658.  */
  659. static VOID WriteAsmB(file)
  660.     BPTR file;
  661. {
  662.     register struct MyGadget *g;
  663.     register struct Border   *b;
  664.     register SHORT           *xy;
  665.     register UCOUNT           bc = 0,xyc;
  666.  
  667.     if(Borders.TailPred == (struct MyGadget *)&Borders) return;
  668.  
  669.     g = Borders.Head;
  670.  
  671.     while(1)
  672.     {   b = (struct Border *)g->Gadget.GadgetRender;
  673.         xy = b->XY;
  674.         WriteFormat(file,"XYPairs%ld:\n    DC.W   ",bc++);
  675.         for(xyc = 0;xyc < 10;xyc++) WriteFormat(file,"%ld,",xy[xyc]);
  676.         Seek(file,-1,OFFSET_CURRENT);
  677.         WriteFormat(file,"\n");
  678.         if((g = g->Succ) == (struct MyGadget *)&Borders.Tail) break;
  679.     }
  680.     bc = 0;
  681.     g = Borders.Head;
  682.     while(1)
  683.     {   b = (struct Border *)g->Gadget.GadgetRender;
  684.         WriteFormat(file,"rnd_border%ld:\n",bc);
  685.         WriteFormat(file,"    DC.W    %ld,%ld\n",g->Gadget.LeftEdge,g->Gadget.TopEdge);
  686.  
  687.         WriteFormat(file,"    DC.B    %ld,0\n    DC.B    RP_JAM1,5\n",b->FrontPen);
  688.         WriteFormat(file,"    DC.L    XYPairs%ld,",bc++);
  689.         if((g = g->Succ) == (struct MyGadget *)&Borders.Tail)
  690.         {   WriteFormat(file,"0\n\n");
  691.             break;
  692.         }
  693.         else WriteFormat(file,"rnd_border%ld\n",bc);
  694.     }
  695. }
  696.  
  697. /*
  698.  * write the assembler source code
  699.  */
  700. VOID WriteAsmGadgets()
  701. {
  702.     BPTR                      file;
  703.     register struct MyGadget *gadget;
  704.     struct ColorMap          *cm;
  705.     COUNT                     i,ii;
  706.     USHORT                   *tab,cc;
  707.     ULONG                     rc;
  708.     char                     *str;
  709.  
  710.     strcpy((char *)IODir->fr_HeadLine,"Save Asm Source");
  711.     IODir->fr_Screen = MainScreen;
  712.     IODir->fr_Caller = MainWindow;
  713.     rc = FileRequest(IODir);
  714.     strcpy((char *)&name,(char *)IODir->fr_DirName);
  715.     strcat((char *)&name,(char *)IODir->fr_FileName);
  716.  
  717.     if(rc == FREQ_CANCELED) return;
  718.     else if(rc)
  719.     {   Error("FileRequester won't open !");
  720.         return;
  721.     }
  722.     cm = MainScreen->ViewPort.ColorMap;
  723.     tab = (USHORT *)cm->ColorTable;
  724.     if(!(file = Open((char *)&name,MODE_NEWFILE)))
  725.     {  Error("Can't Open Write File !");
  726.        return;
  727.     }
  728.     SetWindowTitles(MainWindow,(char *)-1L,(char *)"Saving Assembler Source.....");
  729.     buisy();
  730.     disable_window();
  731.     cc = (1 << MainScreen->BitMap.Depth);
  732.     WriteFormat(file,"*-------------------------------------------------\n");
  733.     WriteFormat(file,"* Gadgets created with GadgetEd V2.0\n");
  734.     WriteFormat(file,"* (c) Copyright 1990 by Jaba Development\n");
  735.     WriteFormat(file,"* written by Jan van den Baard\n");
  736.     WriteFormat(file,"*-------------------------------------------------\n\n");
  737.     if(NOT WBSCREEN)
  738.     {   WriteFormat(file,"Colors:\n");
  739.         for(ii=0;ii<cc;ii+=8)
  740.         {   WriteFormat(file,"    DC.W    ");
  741.             for(i=0;i<8;i++)
  742.               if((ii+i) < cc) WriteFormat(file,"$%04lx,",tab[ii+i]);
  743.             Seek(file,-1,OFFSET_CURRENT);
  744.             WriteFormat(file,"\n");
  745.         }
  746.         WriteFormat(file,"\n");
  747.     }
  748.     split();
  749.     WriteAsmB(file);
  750.     WriteAsmWDT(file);
  751.     WriteAsmCRG(file);
  752.     if(GadgetCount)
  753.     {   for(gadget = Gadgets.Head;gadget != (struct MyGadget *)&Gadgets.Tail;gadget = gadget->Succ)
  754.         {   if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET))
  755.             {   WriteAsmPinfo(file,gadget);
  756.                 if(NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE))
  757.                     WriteAsmImage(file,gadget,STDPRP);
  758.             }
  759.             if(TestBits((ULONG)gadget->Gadget.GadgetType,STRGADGET))
  760.                 WriteAsmSinfo(file,gadget);
  761.             if((NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE)) AND
  762.                (NOT TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET)))
  763.                 WriteAsmBorder(file,gadget);
  764.             if(TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE))
  765.                 WriteAsmImage(file,gadget,RENDER);
  766.             if((TestBits((ULONG)gadget->Gadget.Flags,GADGHIMAGE)) AND
  767.                (NOT TestBits((ULONG)gadget->Gadget.Flags,GADGHBOX)))
  768.                 WriteAsmImage(file,gadget,SELECT);
  769.             if(gadget->Gadget.GadgetText)
  770.                 WriteAsmTexts(file,gadget);
  771.             WriteAsmGadget(file,gadget);
  772.             if(str = IoErrToStr())
  773.             {   enable_window();
  774.                 Close(file);
  775.                 Error(str);
  776.                 return;
  777.             }
  778.         }
  779.     }
  780.     gadget = Gadgets.TailPred;
  781.     if(NOT WBSCREEN) WriteAsmScreen(file);
  782.     WriteAsmRW(file);
  783.     if(NOT WBSCREEN)  WriteFormat(file,"\nCOLORCOUNT   EQU   %ld",cc);
  784.     if(NOT REQUESTER) WriteFormat(file,"\nNEWWINDOW:   DC.L   %s",&wlb);
  785.     else              WriteFormat(file,"\nREQUESTER:   DC.L   requester");
  786.     if(NOT WBSCREEN)  WriteFormat(file,"\nNEWSCREEN:   DC.L   ns");
  787.     if(GadgetCount)
  788.         WriteFormat(file,"\nFIRSTGADGET: DC.L   %s",&Gadgets.TailPred->GadgetLabel);
  789.     if(TextGadget.GadgetText)
  790.         WriteFormat(file,"\nFIRSTTEXT:   DC.L   rnd_text0");
  791.     if(Borders.TailPred != (struct MyGadget *)&Borders)
  792.         WriteFormat(file,"\nFIRSTBORDER: DC.L   rnd_border0");
  793.     WriteFormat(file,"\n");
  794.     if(str = IoErrToStr()) Error(str);
  795.     Close(file);
  796.     join();
  797.     enable_window();
  798.     ok();
  799.     return;
  800. }
  801.  
  802. /*
  803.  * write the C border structure
  804.  */
  805. static VOID WriteCBorder(file,gadget)
  806.     BPTR            file;
  807.     struct MyGadget *gadget;
  808. {
  809.     struct Border *border;
  810.     SHORT         *XY;
  811.     COUNT          i;
  812.  
  813.     border = (struct Border *)gadget->Gadget.GadgetRender;
  814.     XY     = border->XY;
  815.     WriteFormat(file,"SHORT %s_pairs[] = {\n  ",&gadget->GadgetLabel);
  816.     for(i=0;i<10;i++) WriteFormat(file,"%ld,",XY[i]);
  817.     Seek(file,-1,OFFSET_CURRENT);
  818.     WriteFormat(file," };\n\n");
  819.     WriteFormat(file,"struct Border %s_bord = {\n",&gadget->GadgetLabel);
  820.     WriteFormat(file,"  %ld,%ld,",border->LeftEdge,border->TopEdge);
  821.     WriteFormat(file,"%ld,%ld,",border->FrontPen,border->BackPen);
  822.     WriteDrMd(file,border->DrawMode,FALSE);
  823.     WriteFormat(file,",%ld,",border->Count);
  824.     WriteFormat(file,"(SHORT *)&%s_pairs,NULL };\n\n",&gadget->GadgetLabel);
  825. }
  826.  
  827. /*
  828.  * write the C image structure
  829.  */
  830. static VOID WriteCImage(file,gadget,which)
  831.     BPTR            file;
  832.     struct MyGadget *gadget;
  833.     UBYTE            which;
  834. {
  835.     struct Image *image;
  836.     register USHORT       *data;
  837.     register COUNT        i,ii;
  838.     ULONG        data_size;
  839.  
  840.     if(which == RENDER) image = (struct Image *)gadget->Gadget.GadgetRender;
  841.     else image = (struct Image *)gadget->Gadget.SelectRender;
  842.     data  = image->ImageData;
  843.     if(which != STDPRP)
  844.     {   if(which == SELECT)
  845.           WriteFormat(file,"USHORT %s_hdata[] = {\n",gadget->GadgetLabel);
  846.         else
  847.           WriteFormat(file,"USHORT %s_data[] = {\n",gadget->GadgetLabel);
  848.         data_size = (RASSIZE(image->Width,image->Height) * image->Depth);
  849.         for(i=0;i<(data_size >> 1);i+=8)
  850.         {   for(ii=0;ii<8;ii++)
  851.             {   if(i+ii < (data_size >> 1)) WriteFormat(file,"  0x%04lx,",data[i+ii]);
  852.             }
  853.             WriteFormat(file,"\n");
  854.         }
  855.         Seek(file,-2,OFFSET_CURRENT);
  856.         WriteFormat(file," }; \n\n");
  857.     }
  858.     if(which == SELECT)
  859.       WriteFormat(file,"struct Image %s_himage = {\n",&gadget->GadgetLabel);
  860.     else
  861.       WriteFormat(file,"struct Image %s_image = {\n",&gadget->GadgetLabel);
  862.     WriteFormat(file,"  %ld,%ld,",image->LeftEdge,image->TopEdge);
  863.     WriteFormat(file,"%ld,%ld,",image->Width,image->Height);
  864.     WriteFormat(file,"%ld,",image->Depth);
  865.     if(which != STDPRP)
  866.     {   if(which == SELECT)
  867.           WriteFormat(file,"(USHORT *)&%s_hdata,",&gadget->GadgetLabel);
  868.         else
  869.           WriteFormat(file,"(USHORT *)&%s_data,",&gadget->GadgetLabel);
  870.     }
  871.     else
  872.        WriteFormat(file,"NULL,");
  873.     WriteFormat(file,"0x%02lx,",image->PlanePick);
  874.     WriteFormat(file,"0x%02lx,",image->PlaneOnOff);
  875.     WriteFormat(file,"NULL };\n\n");
  876. }
  877.  
  878. /*
  879.  * write the C PropInfo structure
  880.  */
  881. static VOID WriteCPinfo(file,gadget)
  882.     BPTR            file;
  883.     struct MyGadget *gadget;
  884. {
  885.     struct PropInfo *info;
  886.  
  887.     info = (struct PropInfo *)gadget->Gadget.SpecialInfo;
  888.     WriteFormat(file,"struct PropInfo %s_info = {\n  ",&gadget->GadgetLabel);
  889.     WritePFlags(file,info);
  890.     WriteFormat(file,",0x%04lx,",info->HorizPot);
  891.     WriteFormat(file,"0x%04lx,",info->VertPot);
  892.     WriteFormat(file,"0x%04lx,",info->HorizBody);
  893.     WriteFormat(file,"0x%04lx,",info->VertBody);
  894.     WriteFormat(file,"0,0,0,0,0,0 };\n\n");
  895. }
  896.  
  897. /*
  898.  * write the C StringInfo structure
  899.  */
  900. static VOID WriteCSinfo(file,gadget)
  901.     BPTR            file;
  902.     struct MyGadget *gadget;
  903. {
  904.     struct StringInfo *info;
  905.  
  906.     info = (struct StringInfo *)gadget->Gadget.SpecialInfo;
  907.     WriteFormat(file,"UBYTE %s_buf[%ld] = %lc%s%lc;\n\n",&gadget->GadgetLabel,
  908.                                                  info->MaxChars,'"',
  909.                                                  info->Buffer,'"');
  910.     if(info->UndoBuffer)
  911.       WriteFormat(file,"UBYTE %s_ubuf[%ld];\n\n",&gadget->GadgetLabel,info->MaxChars);
  912.     WriteFormat(file,"struct StringInfo %s_info = {\n",&gadget->GadgetLabel);
  913.     WriteFormat(file,"  (UBYTE *)&%s_buf,",&gadget->GadgetLabel);
  914.     if(info->UndoBuffer)
  915.        WriteFormat(file,"(UBYTE *)&%s_ubuf,",&gadget->GadgetLabel);
  916.     else
  917.        WriteFormat(file,"NULL,");
  918.     WriteFormat(file,"0,%ld,",info->MaxChars);
  919.     WriteFormat(file,"0,0,0,0,0,0,");
  920.     WriteFormat(file,"NULL,NULL,NULL };\n\n");
  921. }
  922.  
  923. /*
  924.  * write the C Gadget structure
  925.  */
  926. static VOID WriteCGadget(file,gadget)
  927.     BPTR            file;
  928.     struct MyGadget *gadget;
  929. {
  930.     struct Gadget    *gad;
  931.     struct MyGadget  *next;
  932.     struct IntuiText *itext;
  933.  
  934.     gad = &gadget->Gadget;
  935.  
  936.     WriteFormat(file,"#define %s_ID    %ld\n\n",&gadget->GadgetLabel,gad->GadgetID);
  937.     WriteFormat(file,"struct Gadget %s = {\n  ",&gadget->GadgetLabel);
  938.     if(gadget == Gadgets.Head)
  939.     {   if(NOT REQUESTER)
  940.         {   if((TextGadget.GadgetText) OR
  941.                (Borders.TailPred != (struct MyGadget *)&Borders)) WriteFormat(file,"&rnd,");
  942.             else WriteFormat(file,"NULL,");
  943.         }
  944.         else WriteFormat(file,"NULL,");
  945.     }
  946.     else
  947.        WriteFormat(file,"&%s,",&(gadget->Pred->GadgetLabel));
  948.     WriteFormat(file,"%ld,%ld,",gad->LeftEdge,gad->TopEdge);
  949.     WriteFormat(file,"%ld,%ld,\n  ",gad->Width,gad->Height);
  950.     WriteFlags(file,gadget);
  951.     WriteFormat(file,",\n  ");
  952.     WriteActivation(file,gadget);
  953.     WriteFormat(file,",\n  ");
  954.     WriteType(file,gadget);
  955.     if((TestBits((ULONG)gad->Flags,GADGIMAGE)) ||
  956.        (TestBits((ULONG)gad->GadgetType,PROPGADGET)))
  957.       WriteFormat(file,",\n  (APTR)&%s_image,",&gadget->GadgetLabel);
  958.     else
  959.       WriteFormat(file,",\n  (APTR)&%s_bord,",&gadget->GadgetLabel);
  960.     if((TestBits((ULONG)gad->Flags,GADGHIMAGE)) AND
  961.        (NOT TestBits((ULONG)gad->Flags,GADGHBOX)))
  962.       WriteFormat(file,"(APTR)&%s_himage,\n  ",&gadget->GadgetLabel);
  963.     else
  964.       WriteFormat(file,"NULL,\n  ");
  965.     if((itext = gad->GadgetText))
  966.     {   if(itext->NextText)
  967.           WriteFormat(file,"&%s_text[0],NULL,",&gadget->GadgetLabel);
  968.         else
  969.           WriteFormat(file,"&%s_text,NULL,",&gadget->GadgetLabel);
  970.     }
  971.     else WriteFormat(file,"NULL,NULL,");
  972.     if(gad->SpecialInfo)
  973.       WriteFormat(file,"(APTR)&%s_info,",&gadget->GadgetLabel);
  974.     else
  975.       WriteFormat(file,"NULL,");
  976.     WriteFormat(file,"%s_ID,NULL };\n\n",&gadget->GadgetLabel);
  977. }
  978.  
  979. /*
  980.  * write the C IntuiText structures
  981.  */
  982. static VOID WriteCTexts(file,gadget)
  983.     BPTR            file;
  984.     struct MyGadget *gadget;
  985. {
  986.     register struct IntuiText *itext;
  987.     COUNT    i=0;
  988.  
  989.     if((itext = gadget->Gadget.GadgetText))
  990.     {   if(itext->NextText)
  991.           WriteFormat(file,"struct IntuiText %s_text[] = {\n",&gadget->GadgetLabel);
  992.         else
  993.           WriteFormat(file,"struct IntuiText %s_text = {\n",&gadget->GadgetLabel);
  994.         while(1)
  995.         {   WriteFormat(file,"  %ld,%ld,",itext->FrontPen,itext->BackPen);
  996.             WriteDrMd(file,itext->DrawMode,FALSE);
  997.             WriteFormat(file,",%ld,%ld,NULL,",itext->LeftEdge,itext->TopEdge);
  998.             WriteFormat(file,"(UBYTE *)%lc%s%lc,",'"',itext->IText,'"');
  999.             if(itext->NextText)
  1000.               WriteFormat(file,"&%s_text[%ld],\n  ",&gadget->GadgetLabel,i++);
  1001.             else
  1002.               WriteFormat(file,"NULL");
  1003.             if(!(itext = itext->NextText)) break;
  1004.        }
  1005.        WriteFormat(file," };\n\n");
  1006.     }
  1007. }
  1008.  
  1009. /*
  1010.  * write the C NewScreen structure
  1011.  */
  1012. static VOID WriteCScreen(file)
  1013.     BPTR file;
  1014. {
  1015.     WriteFormat(file,"struct NewScreen ns = {\n");
  1016.     WriteFormat(file,"  0,0,%ld,%ld,",MainScreen->Width,MainScreen->Height);
  1017.     WriteFormat(file,"%ld,",MainScreen->BitMap.Depth);
  1018.     WriteFormat(file,"-1,-1,");
  1019.     if(MainScreen->BitMap.Depth == 5) WriteFormat(file,"NULL,");
  1020.     else WriteFormat(file,"HIRES,");
  1021.     WriteFormat(file,"CUSTOMSCREEN,NULL,NULL,NULL,NULL };\n\n");
  1022. }
  1023.  
  1024. /*
  1025.  * write the C window/requester structure
  1026.  */
  1027. static VOID WriteCRW(file)
  1028.     BPTR file;
  1029. {
  1030.     struct IntuiText *t;
  1031.     if(REQUESTER)
  1032.     {   WriteFormat(file,"struct Requester requester = {\n  NULL,");
  1033.         WriteFormat(file,"%ld,%ld,",(MainWindow->LeftEdge + MainWindow->BorderLeft),
  1034.                                     (MainWindow->TopEdge + MainWindow->BorderTop));
  1035.         WriteFormat(file,"%ld,%ld,",MainWindow->GZZWidth,MainWindow->GZZHeight);
  1036.         if(GadgetCount)
  1037.             WriteFormat(file,"0,0,&%s,",&Gadgets.TailPred->GadgetLabel);
  1038.         else
  1039.             WriteFormat(file,"0,0,NULL,");
  1040.         if(Borders.TailPred != (struct MyGadget *)&Borders)
  1041.         {   if(Borders.Head->Succ != (struct MyGadget *)&Borders.Tail)
  1042.               WriteFormat(file,"&rnd_border[0],");
  1043.             else
  1044.               WriteFormat(file,"&rnd_border,");
  1045.         }
  1046.         else WriteFormat(file,"NULL,");
  1047.         if((t = TextGadget.GadgetText))
  1048.         {   if(t->NextText) WriteFormat(file,"&rnd_text[0],");
  1049.             else WriteFormat(file,"&rnd_text,");
  1050.         }
  1051.         else WriteFormat(file,"NULL,");
  1052.         WriteFormat(file,"NULL,%ld,",BackFill);
  1053.         WriteFormat(file,"NULL,NULL,NULL,NULL,NULL };\n\n");
  1054.     }
  1055.     else
  1056.     {   WriteFormat(file,"struct NewWindow %s = {\n  ",&wlb);
  1057.         WriteFormat(file,"%ld,%ld,%ld,%ld,",MainWindow->LeftEdge,MainWindow->TopEdge,
  1058.                                             MainWindow->Width,MainWindow->Height);
  1059.         WriteFormat(file,"%ld,%ld,\n  ",MainWindow->DetailPen,MainWindow->BlockPen);
  1060.         WriteIFlags(file);
  1061.         WriteFormat(file,",\n  ");
  1062.         WriteWFlags(file);
  1063.         WriteFormat(file,",\n");
  1064.         if(GadgetCount)
  1065.             WriteFormat(file,"  &%s,NULL,\n",Gadgets.TailPred->GadgetLabel);
  1066.         else
  1067.             WriteFormat(file,"  NULL,NULL,\n");
  1068.         WriteFormat(file,"  (UBYTE *)%lc%s%lc,NULL,NULL,\n",'"',&wdt,'"');
  1069.         WriteFormat(file,"  %ld,%ld,%ld,%ld,",MainWindow->MinWidth,
  1070.                                               MainWindow->MinHeight,
  1071.                                               MainWindow->MaxWidth,
  1072.                                               MainWindow->MaxHeight);
  1073.         if(WBSCREEN) WriteFormat(file,"WBENCHSCREEN };\n\n");
  1074.         else         WriteFormat(file,"CUSTOMSCREEN };\n\n");
  1075.     }
  1076. }
  1077.  
  1078. /*
  1079.  * write the C window/requester texts structures
  1080.  */
  1081. static VOID WriteCWDT(file)
  1082.     BPTR file;
  1083. {
  1084.     register struct IntuiText *t, *t1;
  1085.     register UCOUNT i = 1;
  1086.  
  1087.     if(NOT TextGadget.GadgetText) return;
  1088.  
  1089.     t = TextGadget.GadgetText;
  1090.     if(t->NextText)
  1091.       WriteFormat(file,"struct IntuiText rnd_text[] = {\n  ");
  1092.     else
  1093.       WriteFormat(file,"struct IntuiText rnd_text = {\n  ");
  1094.     while(1)
  1095.     {   WriteFormat(file,"%ld,%ld,",t->FrontPen,t->BackPen);
  1096.         WriteDrMd(file,t->DrawMode,FALSE);
  1097.         WriteFormat(file,",%ld,%ld,NULL,",t->LeftEdge,t->TopEdge);
  1098.         WriteFormat(file,"(UBYTE *)%lc%s%lc,",'"',t->IText,'"');
  1099.         if(t->NextText)
  1100.           WriteFormat(file,"&rnd_text[%ld],\n  ",i++);
  1101.         else
  1102.           WriteFormat(file,"NULL");
  1103.         if(!(t = t->NextText)) break;
  1104.     }
  1105.     WriteFormat(file," };\n\n");
  1106. }
  1107.  
  1108. /*
  1109.  * write the C special render gadget
  1110.  */
  1111. static VOID WriteCRG(file)
  1112.     BPTR file;
  1113. {
  1114.     struct IntuiText *t;
  1115.  
  1116.     if((TextGadget.GadgetText) OR
  1117.        (Borders.TailPred != (struct MyGadget *)&Borders))
  1118.     {   if(NOT REQUESTER)
  1119.         {   WriteFormat(file,"struct Gadget rnd = {\n  ");
  1120.             WriteFormat(file,"NULL,0,0,1,1,GADGHNONE,NULL,BOOLGADGET,\n");
  1121.  
  1122.             if(Borders.TailPred != (struct MyGadget *)&Borders)
  1123.             {   if(Borders.Head->Succ != (struct MyGadget *)&Borders.Tail)
  1124.                   WriteFormat(file,"  (APTR)&rnd_border[0],NULL,");
  1125.                 else
  1126.                   WriteFormat(file,"  (APTR)&rnd_border,NULL,");
  1127.             }
  1128.             else WriteFormat(file,"  NULL,NULL,");
  1129.             if((t = TextGadget.GadgetText))
  1130.             {   if(t->NextText) WriteFormat(file,"&rnd_text[0],");
  1131.                 else WriteFormat(file,"&rnd_text,");
  1132.             }
  1133.             else WriteFormat(file,"NULL,");
  1134.             WriteFormat(file,"NULL,NULL,NULL,NULL };\n\n");
  1135.         }
  1136.     }
  1137. }
  1138.  
  1139. /*
  1140.  * write the C Border structures
  1141.  */
  1142. static VOID WriteCB(file)
  1143.     BPTR file;
  1144. {
  1145.     register struct MyGadget *g;
  1146.     register struct Border   *b;
  1147.     register SHORT           *xy;
  1148.     register UCOUNT           bc = 0,xyc;
  1149.  
  1150.     if(Borders.TailPred == (struct MyGadget *)&Borders) return;
  1151.  
  1152.     g = Borders.Head;
  1153.  
  1154.     while(1)
  1155.     {   b = (struct Border *)g->Gadget.GadgetRender;
  1156.         xy = b->XY;
  1157.         WriteFormat(file,"SHORT XYPairs%ld[] = {\n  ",bc++);
  1158.         for(xyc = 0;xyc < 10;xyc++) WriteFormat(file,"%ld,",xy[xyc]);
  1159.         Seek(file,-1,OFFSET_CURRENT);
  1160.         WriteFormat(file," };\n");
  1161.         if((g = g->Succ) == (struct MyGadget *)&Borders.Tail) break;
  1162.     }
  1163.     bc = 0;
  1164.     g = Borders.Head;
  1165.     WriteFormat(file,"struct Border rnd_border");
  1166.     if(g->Succ != (struct MyGadget *)&Borders.Tail) WriteFormat(file,"[] = {\n");
  1167.     else WriteFormat(file," = {\n");
  1168.     while(1)
  1169.     {   b = (struct Border *)g->Gadget.GadgetRender;
  1170.         WriteFormat(file,"  %ld,%ld,",g->Gadget.LeftEdge,g->Gadget.TopEdge);
  1171.         WriteFormat(file,"%ld,0,JAM1,5,(SHORT *)&XYPairs%ld,",b->FrontPen,bc++);
  1172.         if((g = g->Succ) == (struct MyGadget *)&Borders.Tail)
  1173.         {   WriteFormat(file,"NULL };\n\n");
  1174.             break;
  1175.         }
  1176.         else WriteFormat(file,"&rnd_border[%ld],\n",bc);
  1177.     }
  1178. }
  1179.  
  1180. /*
  1181.  * write the C source code
  1182.  */
  1183. VOID WriteCGadgets()
  1184. {
  1185.     BPTR                      file;
  1186.     register struct MyGadget *gadget;
  1187.     struct ColorMap          *cm;
  1188.     COUNT                     i,ii;
  1189.     USHORT                   *tab,cc;
  1190.     ULONG                     rc;
  1191.     char                     *str;
  1192.  
  1193.     strcpy((char *)IODir->fr_HeadLine,"Save C Source");
  1194.     IODir->fr_Screen = MainScreen;
  1195.     IODir->fr_Caller = MainWindow;
  1196.     rc = FileRequest(IODir);
  1197.     strcpy((char *)&name,(char *)IODir->fr_DirName);
  1198.     strcat((char *)&name,(char *)IODir->fr_FileName);
  1199.  
  1200.     if(rc == FREQ_CANCELED) return;
  1201.     else if(rc)
  1202.     {   Error("FileRequester won't open !");
  1203.         return;
  1204.     }
  1205.     cm = MainScreen->ViewPort.ColorMap;
  1206.     tab = (USHORT *)cm->ColorTable;
  1207.     if(NOT(file = Open((char *)&name,MODE_NEWFILE)))
  1208.     {   Error("Can't open write file !");
  1209.         return;
  1210.     }
  1211.     SetWindowTitles(MainWindow,(char *)-1L,(char *)"Saving C Source.....");
  1212.     buisy();
  1213.     disable_window();
  1214.     cc = (1 << MainScreen->BitMap.Depth);
  1215.     WriteFormat(file,"/*-------------------------------------------------*\n");
  1216.     WriteFormat(file,"  Gadgets created with GadgetEd V2.0\n");
  1217.     WriteFormat(file,"  (c) Copyright 1990 by Jaba Development\n");
  1218.     WriteFormat(file,"  written by Jan van den Baard\n");
  1219.     WriteFormat(file," *-------------------------------------------------*/\n\n");
  1220.     if(NOT WBSCREEN)
  1221.     {   WriteFormat(file,"USHORT Colors[] = {\n");
  1222.         for(ii=0;ii<cc;ii+=8)
  1223.         {   for(i=0;i<8;i++)
  1224.               if((ii+i) < cc) WriteFormat(file,"  0x%04lx,",tab[ii+i]);
  1225.             WriteFormat(file,"\n");
  1226.         }
  1227.         Seek(file,-2,OFFSET_CURRENT);
  1228.         WriteFormat(file," };\n\n");
  1229.     }
  1230.     split();
  1231.     WriteCB(file);
  1232.     WriteCWDT(file);
  1233.     WriteCRG(file);
  1234.     if(GadgetCount)
  1235.     {   for(gadget = Gadgets.Head;gadget != (struct MyGadget *)&Gadgets.Tail;gadget = gadget->Succ)
  1236.         {   if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET))
  1237.             {   WriteCPinfo(file,gadget);
  1238.                 if(NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE))
  1239.                     WriteCImage(file,gadget,STDPRP);
  1240.             }
  1241.             if(TestBits((ULONG)gadget->Gadget.GadgetType,STRGADGET))
  1242.                 WriteCSinfo(file,gadget);
  1243.             if((NOT TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE)) AND
  1244.                (NOT TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET)))
  1245.                 WriteCBorder(file,gadget);
  1246.             if(TestBits((ULONG)gadget->Gadget.Flags,GADGIMAGE))
  1247.                 WriteCImage(file,gadget,RENDER);
  1248.             if((TestBits((ULONG)gadget->Gadget.Flags,GADGHIMAGE)) AND
  1249.                (NOT TestBits((ULONG)gadget->Gadget.Flags,GADGHBOX)))
  1250.                 WriteCImage(file,gadget,SELECT);
  1251.             if(gadget->Gadget.GadgetText)
  1252.                 WriteCTexts(file,gadget);
  1253.             WriteCGadget(file,gadget);
  1254.             if(str = IoErrToStr())
  1255.             {   Close(file);
  1256.                 enable_window();
  1257.                 Error(str);
  1258.                 return;
  1259.             }
  1260.         }
  1261.     }
  1262.     gadget = Gadgets.TailPred;
  1263.     if(NOT WBSCREEN) WriteCScreen(file);
  1264.     WriteCRW(file);
  1265.     if(NOT WBSCREEN)  WriteFormat(file,"\n#define COLORCOUNT  %ld",cc);
  1266.     if(NOT REQUESTER) WriteFormat(file,"\n#define NEWWINDOW   &%s",&wlb);
  1267.     else              WriteFormat(file,"\n#define REQUESTER   &requester");
  1268.     if(NOT WBSCREEN)  WriteFormat(file,"\n#define NEWSCREEN   &ns");
  1269.     if(GadgetCount)
  1270.         WriteFormat(file,"\n#define FIRSTGADGET &%s",&Gadgets.TailPred->GadgetLabel);
  1271.     if(TextGadget.GadgetText)
  1272.     {   WriteFormat(file,"\n#define FIRSTTEXT   &");
  1273.         if(TextGadget.GadgetText->NextText)
  1274.           WriteFormat(file,"rnd_text[0]");
  1275.         else
  1276.           WriteFormat(file,"rnd_text");
  1277.     }
  1278.     if(Borders.TailPred != (struct MyGadget *)&Borders)
  1279.     {   WriteFormat(file,"\n#define FIRSTBORDER &");
  1280.         if(Borders.Head->Succ != (struct MyGadget *)&Borders.Tail)
  1281.           WriteFormat(file,"rnd_border[0]");
  1282.         else
  1283.         WriteFormat(file,"rnd_border");
  1284.     }
  1285.     WriteFormat(file,"\n");
  1286.     if(str = IoErrToStr()) Error(str);
  1287.     Close(file);
  1288.     join();
  1289.     enable_window();
  1290.     ok();
  1291.     return;
  1292. }
  1293.